package com.spark.lola.service.sup.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spark.lola.entity.sup.BankInfo;
import com.spark.lola.mapper.sup.BankInfoMapper;
import com.spark.lola.service.sup.IBankInfoService;
import com.spark.lola.support.common.constant.CommonConstant;
import com.spark.lola.support.core.vo.SelectMap;
import com.spark.lola.support.mybatis.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dengyejun
 * @since 2020-04-24
 */
@Service
public class BankInfoServiceImpl extends BaseServiceImpl<BankInfoMapper, BankInfo> implements IBankInfoService {

    @Override
    public List<SelectMap> selectMap(Long supplierId) {
        QueryWrapper<BankInfo> queryWrapper =new QueryWrapper<>();
        queryWrapper.select("id,name");
        queryWrapper.eq("used", CommonConstant.Y);
        if(supplierId.intValue() > 0) {
            queryWrapper.eq("supplier_id", supplierId);
        }
        List<BankInfo> lst = baseMapper.selectList(queryWrapper);
        List<SelectMap> selectMaps =new ArrayList<>();
        if(!CollectionUtils.isEmpty(lst)) {
            lst.forEach(item -> {
                selectMaps.add(new SelectMap(item.getId(), item.getBankName()));
            });
        }
        return selectMaps;
    }

    @Override
    public List<BankInfo> findBySupplierId(Long supplierId) {
        QueryWrapper<BankInfo> query =new QueryWrapper<>();
        query.eq("used",CommonConstant.Y);
        query.eq("supplier_id",supplierId);
        return list(query);
    }
}
